package com.qf.agro.web.controller.crop;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.crop.CropFactory;
import com.qf.agro.service.crop.CropFactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/crop/factory")
public class CropFactoryController {

    @Autowired
    private CropFactoryService cropFactoryService;

    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String name) {
        Page<CropFactory> page = cropFactoryService.findPage(pageNum, pageSize, name);
        return ResultInfo.success(page);
    }

    @PostMapping
    public ResultInfo save(@RequestBody CropFactory cropFactory) {
        cropFactoryService.save(cropFactory);
        return ResultInfo.success(null);
    }

    @PutMapping
    public ResultInfo update(@RequestBody CropFactory cropFactory) {
        cropFactoryService.update(cropFactory);
        return ResultInfo.success(null);
    }

    @DeleteMapping
    public ResultInfo delete(Long id) {
        cropFactoryService.disabled(id);
        return ResultInfo.success(null);
    }
    
}
